package com.sun.controller;

import com.sun.pojo.entity.UserRole;
import com.sun.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author SunRui
 * @description TODO
 * @date 2024/10/5 16:05
 */
@Controller
@ResponseBody
@RequestMapping(value = "/role")
public class RoleController {
    @Autowired
    UserRoleService userRoleService;
    /*
    新增权限
     */
    @PostMapping("addUserRole")
    public int addUserRole(UserRole userRole){
        if (userRoleService.addUserRole(userRole)>0){
            return 1;
        }
        return -1;
    }

    /*
    删除权限
     */
    @PostMapping("deleteUserRole")
    public int deleteUserRole(Integer id){
        if (userRoleService.deleteUserRole(id)>0){
            return 1;
        }
        return -1;
    }

    /*
    修改权限
     */
    @PostMapping("updateRole")
    public int updateRole(UserRole userRole){
        if (userRoleService.updateRole(userRole)>0){
            return 1;
        }
        return -1;
    }
    /*
    查询权限
     */
    @PostMapping("getRoleList")
    public List<UserRole> getRoleList(){
        List<UserRole> userRoles = userRoleService.getRoleList();
        return userRoles;
    }
}
